﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;

namespace SF.Web.UI.mallCs
{
    public class cart
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "syj")
                {
                    usingMsg = "<link href='css/cart.css' rel='stylesheet' />";
                }
                else if (templateType == "weishanggreen")
                {
                    usingMsg = "<link href='css/cartgreen.css' rel='stylesheet' />";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    jsMsg = "$(function () {var count = 0;$('.c_price').each(function () {count += parseFloat($(this).html().replace('¥', '').replace('￥', '').trim());});$('#count').html('￥' + count);});function delshopcar(id) {if (confirm('确认删除该商品?')) {$('#cardIds').text().replace(id + ',', '');$.get('/tools/user_ajax.ashx', { action: 'delete_card', id: id }, function (rs) {if (rs=='') {window.location.reload();} else {alert('删除失败，请刷新页面!');}});}} function cutadd(id, obj) {var newnum = 0;if (obj=='0' || obj==0) {newnum = parseInt($('#rpc_show' + id).html()) - 1;} else {newnum = parseInt($('#rpc_show' + id).html()) + 1;}if (newnum > 0) {var sum = newnum * parseFloat($('#unitprice' + id).val());$('#sum' + id).html('￥' + sum.toFixed(2));$('#totalprice' + id).val(sum);$('#rpc_show' + id).html(newnum);var count = 0;$('.c_price').each(function () {count += parseFloat($(this).html().replace('¥', '').replace('￥', '').trim());});$('#count').html('￥' + count);$.get('/tools/user_ajax.ashx', { action: 'cut_add_card', id: id, num: newnum }, function (rs) {if (rs=='') {} else {alert('修改失败，请刷新页面!');}});}}function payNow() {var ids = $('#cardIds').text();if (ids.length <= 0) {return;}ids = ids.substring(0, ids.length - 1);var id = ids.split(',');var nums = '';for (var i = 0; i < id.length; i++) {nums += $('#rpc_show' + id[i]).text() + ','; }nums = nums.substring(0, nums.length - 1);$.get('/tools/user_ajax.ashx', { 'action': 'save_order', 'type': 'cart', 'id': ids, 'num': nums }, function (result) {if (result != '') {location.href = '../mall/orderdetail.aspx?orderId=' + result;} else {alert('网络繁忙，请稍候再试');}});}";
                }
            }
            return jsMsg;
        }
        public string loaddingHtml(Model.sf_user_info userInfo, string templateType)
        {
            string htmlMsg = "",appWhere ="";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                    string ids="",cardGoods="";
                    BLL.sf_goods_cart bll = new BLL.sf_goods_cart();
                    BLL.sf_goods_info goodsbll = new BLL.sf_goods_info();
                    BLL.sf_goods_amounts amountBll = new BLL.sf_goods_amounts();
                    BLL.sf_goods_size sizeBll = new BLL.sf_goods_size();
                    BLL.sf_goods_color colorBll = new BLL.sf_goods_color();
                    DataTable dt = bll.GetList(" userNum='" + userInfo.userNum + "' and " + appWhere).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            string color_size = "";
                            ids += row["id"] + ",";
                            Model.sf_goods_info goodsInfo = goodsbll.GetModel(" goodsNum='" + row["goodsNum"] + "' and " +appWhere);
                            if (!string.IsNullOrEmpty(row["amountId"].ToString()) && Convert.ToInt32(row["amountId"].ToString())>0)
                            {
                                Model.sf_goods_amounts amount = amountBll.GetModel(Convert.ToInt32(row["amountId"]));
                                color_size = "尺码：" + sizeBll.GetModel(Convert.ToInt64(amount.sizeId)).sizeName + "&nbsp;&nbsp;颜色：" + colorBll.GetModel(Convert.ToInt64(amount.colorId)).colorName;
                            }
                            cardGoods += "<div class='cartdiv'><div class='cartlist clearfix'><div class='space10'></div><div class='cartlistinner clearfix'><a href='###' class='cart_orderlist_i'><img style='display: inline;' src='" + goodsInfo.showImgs + "' height='101' width='80' /></a><div class='cart_orderlist_info'><a href='###'><p class='cart_g_name' title='" + row["carNum"] + "'>" + row["carNum"] + "</p><p class='cart_b_name'>" + goodsInfo.names + "</p><p class='c-grey'>单价：￥" + row["price"] + "</p><p class='c-grey'>" + color_size + "</p><p class='space5'></p></a><div class='amount-confirm-box'><a id='cut_a' href='javascript:cutadd(" + row["id"] + ",0);' class='amount-action amount-action-min '>-</a><span id='rpc_show" + row["id"] + "' class='amount-text'>" + row["numbers"] + "</span> <a href='javascript:cutadd(" + row["id"] + ",1);' class='amount-action amount-action-max'>+</a></div></div><a class='cart_orderlist_p' href='###'><span id='sum" + row["id"] + "' class='c_price'>¥ " + row["totalPrice"] + "</span><span class='fontstyle'>抵制假货</span><input id='unitprice" + row["id"] + "' style='display:none;' value='" + row["price"] + "' type='text' /></a><span class='delete'><a href='javascript:delshopcar(" + row["id"] + ");'><img src='imgs/74ff20009b.scan_layer-33.png' height='22' width='22' /></a></span></div></div> </div>";
                        }
                    }
                    string nodataHtml = "";
                    if (string.IsNullOrEmpty(cardGoods))
                    {
                        nodataHtml = "<div class='u-module u-default-page'><div class='u-default-logo'><span class='u-d-icon i-d-cart'></span></div><p class='u-default-text'>购物车历史没发现商品哦</p><a href='Index.aspx' class='u-default-btn'>先去首页逛逛吧</a></div></div>";
                    }
                    htmlMsg = "<body><form id='form1' runat='server'><header id='header' class='u-header clearfix'><div class='u-hd-left f-left'><a href='javascript:history.back();' class='J_backToPrev'><span class='u-icon-px i-hd-back'></span></a></div><span class='u-hd-tit'>购物车</span></header><span style='display:none;' id='cardIds'>" + ids + "</span><div id='nodata' runat='server' class='u-cart-wrapper u-module'><div style='display: none;' class='animate-loading'></div>" + nodataHtml + "<div id='cart_list'><div class='space10'></div>" + cardGoods + "<div class='space10'></div><div style='width:100%;height:80px;'></div><div class='navbar navbar-default navbar-fixed-bottom'><div class='saveguid'><span></span>100%正品保证、抵制假货</div><div class='container nav-current-box checkout-box'><div class='navbar-header'><p class='totle'>总金：<span id='count' class='price'>¥0.00</span></p><span>专注品质与服务</span></div><div class='navbar-brand'><a class='btn btn-large btn-purple' href='javascript:;' onclick='payNow()'>立即支付</a></div></div></div></div></form></body>";
                }
            }
            return htmlMsg;
        }
    }
}
